package routers

import (
	"html/template"

	"github.com/yjp211/web"

	"mutu/filters"
	"mutu/handlers"
	"mutu/misc/conf"
	"mutu/misc/typedef"
)

func Index(ctx *web.Context) {

	t, _ := template.ParseFiles("templates/index.html")
	data := typedef.Dict{
		"QQCode": conf.GetString("OauthQQCode", ""),
		"WBCode": conf.GetString("OauthWBCode", ""),
		"WXCode": conf.GetString("OauthWXCode", ""),
	}
	t.Execute(ctx, data)
}

func init() {
	web.Get("/", Index)

	web.Get("/auth/index", handlers.AuthHandler.Index)
	web.Get("/auth/oauthurl", handlers.AuthHandler.OauthUrl)
	web.Get("/auth/callback", handlers.AuthHandler.CallBack)
	web.Get("/auth/jump", handlers.AuthHandler.OauthJump)
	web.Get("/auth/pwlogin", handlers.AuthHandler.PasswdLogin)
	web.Get("/auth/info", handlers.AuthHandler.OauthInfo).Filter(filters.NeedLogin)
	web.Get("/auth/logout", handlers.AuthHandler.Logout).Filter(filters.NeedLogin)

	web.Get("/resource/tag/classes", handlers.TagHandler.GetAllClasses)
	web.Get("/resource/tag/byclass", handlers.TagHandler.GetTagsByClass)
	web.Get("/resource/tag/byclassname", handlers.TagHandler.GetTagsByClassName)
	web.Get("/resource/tag/all", handlers.TagHandler.GetAllTags)
	web.Get("/resource/tag/all/withcount", handlers.TagHandler.GetAllTagsWithCount)

	web.Get("/resource/category/children", handlers.CategoryHandler.GetChildren)
	web.Get("/resource/category/parent", handlers.CategoryHandler.GetParent)
	web.Get("/resource/category/all", handlers.CategoryHandler.GetAllCategory)
	web.Get("/resource/category/all/withcount", handlers.CategoryHandler.GetAllCategoryWithCount)

	web.Get("/resource/upload/index", handlers.UploadHandler.Index)
	web.Get("/resource/upload/token", handlers.UploadHandler.Token).Filter(filters.NeedLogin)
	web.Post("/resource/upload/callback", handlers.UploadHandler.CallBack)

	web.Get("/resource/matter/create/index", handlers.MatterHandler.CreateIndex).Filter(filters.NeedLogin)
	web.Get("/resource/matter/manage/index", handlers.MatterHandler.ManageIndex).Filter(filters.NeedLogin)
	web.Get("/resource/matter/edit/index", handlers.MatterHandler.EditIndex).Filter(filters.NeedLogin)

	web.Get("/resource/matter/count", handlers.MatterHandler.GetCount)

	web.Get("/resource/matter/all", handlers.MatterHandler.All)
	web.Get("/resource/matter/all/by/cat", handlers.MatterHandler.AllByCat)
	web.Get("/resource/matter/all/by/tag", handlers.MatterHandler.AllByTag)

	web.Post("/resource/matter/create", handlers.MatterHandler.Create).Filter(filters.NeedLogin)
	web.Post("/resource/matter/edit", handlers.MatterHandler.Edit).Filter(filters.NeedLogin)
	web.Get("/resource/matter/delete", handlers.MatterHandler.Delete).Filter(filters.NeedLogin)

	web.Get("/resource/binder/create/index", handlers.BinderHandler.CreateIndex).Filter(filters.NeedLogin)
	web.Get("/resource/binder/manage/index", handlers.BinderHandler.ManageIndex2).Filter(filters.NeedLogin)
	web.Get("/resource/binder/edit/index", handlers.BinderHandler.EditIndex).Filter(filters.NeedLogin)

	web.Post("/resource/binder/create", handlers.BinderHandler.Create).Filter(filters.NeedLogin)
	web.Post("/resource/binder/edit", handlers.BinderHandler.Edit).Filter(filters.NeedLogin)
	web.Get("/resource/binder/delete", handlers.BinderHandler.Delete).Filter(filters.NeedLogin)
	web.Get("/resource/binder/item/add", handlers.BinderHandler.AddItem).Filter(filters.NeedLogin)
	web.Get("/resource/binder/item/remove", handlers.BinderHandler.RemoveItem).Filter(filters.NeedLogin)
	web.Get("/resource/binder/item/list", handlers.BinderHandler.GetItems).Filter(filters.NeedLogin)

	web.Get("/resource/download/geturl", handlers.DownloadHandler.GetUrl).Filter(filters.NeedLogin)
	web.Get("/resource/download/records", handlers.DownloadHandler.GetRecords).Filter(filters.NeedLogin)

	web.Get("/ugc/comment/add", handlers.CommentHandler.AddRelComment).Filter(filters.NeedLogin)
	web.Get("/ugc/comment/remove", handlers.CommentHandler.RemoveRelComment).Filter(filters.NeedLogin)
	web.Get("/ugc/comment/list", handlers.CommentHandler.GetRelComments).Filter(filters.NeedLogin)
	web.Get("/ugc/comment/user", handlers.CommentHandler.GetUserComments).Filter(filters.NeedLogin)
}
